import os
import os.path
import time
import matplotlib.pyplot as plt

filetype_list = []
filesize_list = []
filectime_list = []
filemtime_list = []

def get_all(path):
    filelist = os.listdir(path)
    for filename in filelist:
        path_new = os.path.join(path,filename)
        if os.path.isdir(path_new):
            get_all(path_new)
        elif os.path.isfile(path_new):
            filetype = filename.split(".")[-1]#文件类型
            filetype_list.append(filetype)
            filesize = os.path.getsize(path_new)/1024 #文件大小
            filesize_list.append(filesize)
            filectime = int(os.path.getctime(path_new)) #创建时间
            filemtime = int(os.path.getmtime(path_new)) #修改时间
            time_filectime = time.localtime(filectime)
            time_filemtime = time.localtime(filemtime)
            filectime_list.append(time.strftime("%Y.%m", time_filectime))
            filemtime_list.append(time.strftime("%Y.%m", time_filemtime))
            
path= input("输入路径：").strip()  #由用户指定文件路径
get_all(path)

filectime_list.sort()
filemtime_list.sort()

plt.figure(figsize=(18,9))
plt_a = plt.subplot(221)
plt_b = plt.subplot(222)
plt_c = plt.subplot(223)
plt_d = plt.subplot(224)

plt_a.hist(filetype_list,color='teal',alpha=0.5)
plt_a.set_xlabel("type",fontsize=9)
plt_a.set_ylabel("Number of files",fontsize=9)
plt_a.set_title("FileType",fontsize=9)

plt_b.hist(filesize_list,color='fuchsia',alpha=0.5)
plt_b.set_xlabel("size",fontsize=9)
plt_b.set_ylabel("Number of files",fontsize=9)
plt_b.set_title("FileSize/MB",fontsize=9)

plt_c.hist(filectime_list,color='yellowgreen',alpha=0.5)
plt_c.set_xlabel("FilecTime",fontsize=9)
plt_c.set_ylabel("Number of files",fontsize=9)

plt_d.hist(filemtime_list,color='orange',alpha=0.5)
plt_d.set_xlabel("FilemTime",fontsize=9)
plt_d.set_ylabel("Number of files",fontsize=9)

plt.show()